import java.util.*;
import java.io.*;
import java.math.*;

public class sufarr_test
{
	public static void main(String[] argv) throws IOException
	{
		new sufarr_test().run();
	}
	Scanner in;
	PrintWriter out;

	public void run() throws IOException
	{
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		int n = in.nextInt();
		Random rnd = new Random(357685827L);

		//for (int t = 0; t < 10; t++){
		while (true){
			String str = "";
			String cstr = "";
			for (int i = 0; i < n; i++){
				str = str + (char)('a' + rnd.nextInt(26));
			}

			int[] sufarr = new int[n];
			sufarr[0] = 0;
			cstr += str.charAt(0);
			for (int i = 1; i < n; i++){
				int[] narr = new int[n];
				int nsize = 0;
				char ch = str.charAt(i);
				cstr += ch;
				int[] stack = new int[n];
				int ssize = 0;
				for (int j = 0; j < i; j++){
					while (ssize > 0 && cstr.substring(sufarr[j]).compareTo(cstr.substring(stack[ssize-1])) > 0){
						if ((nsize==0 || ch>cstr.charAt(narr[nsize-1])) && (ch<=cstr.charAt(stack[ssize-1]))){
							narr[nsize++] = i;
						}
						narr[nsize++] = stack[ssize - 1];
						ssize--;
					}
					stack[ssize++] = sufarr[j];
				}
				while (ssize > 0){
					if ((nsize==0 || ch>cstr.charAt(narr[nsize-1])) && (ch<=cstr.charAt(stack[ssize-1]))){
						narr[nsize++] = i;
					}
					narr[nsize++] = stack[ssize - 1];
					ssize--;
				}
				if (ch > cstr.charAt(narr[nsize-1])){
					narr[nsize++] = i;
				}
				sufarr = narr;
				//for (int x = 0; x <= i; x++) System.out.print(sufarr[x] + " ");
				//System.out.println();
			}
			System.out.println(str);
			for (int x = 0; x < n; x++) System.out.print(sufarr[x] + " ");
			System.out.println();
			boolean ok = true;
			for (int i = 1; i < n; i++){
				if (str.substring(sufarr[i-1]).compareTo(str.substring(sufarr[i])) >= 0){
					ok = false;
				}
			}
			System.out.println(ok);
			if (!ok) break;
		}

		out.flush();
	}
}
